/************************************************************************
                        InterfaceLogic.h.cpp - Copyright asaf
*/
#include "InterfaceLogic.h"
#include "Interface.h"
#include "..\dc\DataContainer.h"
// ctor/dtor
InterfaceLogic::InterfaceLogic (Interface &t_ifc ):m_ifc(t_ifc) {m_ifc.setUserPermissionLevel(NONE);}
InterfaceLogic::~InterfaceLogic ( ) { }

auto_ptr<Reply> InterfaceLogic::sendRequest (const Request &request) {
	auto_ptr<Reply>reply=m_ifc.getDc().executeRequest(request);
	switch (reply->getReplyType())
	{
	case LOGIN_SUCCESS:
		//this will retrieve the request.userPermission
		m_ifc.setUserPermissionLevel(USER_PERMISSION_TO_INT(reply->getParameter("PERMISSION",0)));
		m_ifc.setLoggedUserId(request.getParameter("ID"));
		m_ifc.setLoggedUserFname(reply->getParameter("FirstName",0));
		m_ifc.setLoggedUserLname(reply->getParameter("LastName",0));
		return reply;
	case LOGIN_FAILED:
	case LOGOUT_FAILED:
	case LOGOUT_SUCCESS:
		m_ifc.setUserPermissionLevel(NONE);
		return reply;
	default:
		return reply;
	}
}


